<?php
/**
 * Created by PhpStorm.
 * User: fire
 * Date: 2018/10/10
 * Time: 16:36
 */
namespace App\Filters;

use App\User;
use Illuminate\Http\Request;

class ThreadFilters extends Filters {
    protected $filters=['by','popularity','unanswered'];

    public function by($username){
        $user = User::where('name',$username)->firstOrFail();
        return $this->builder->where('user_id',$user->id);
    }

    public function popularity(){
        $this->builder->getQuery()->orders = [];
        return $this->builder->orderBy('replies_count','desc');
    }

    public function unanswered()
    {
        $this->builder->where('replies_count',0);
    }


}